#include "mapsquare.h"

MapSquare::MapSquare(QWidget *parent)
    : QLabel(parent) {
    int w = Pixmaps::getInstance()->map_width,
        h = Pixmaps::getInstance()->map_height;
    setGeometry(-w, -h, w, h);
    setStatus(STATUS_EMPTY);
    _unit_type = UNIT_TYPE_EMPTY;
}

void MapSquare::setStatus(STATUS new_status, bool update_pixmap)
{
    _status = new_status;
    if(update_pixmap){
        if(_status == STATUS_UNCHECKABLE){
            setPixmap(Pixmaps::getInstance()->map0);
        } else if(_status == STATUS_EMPTY){
            setPixmap(Pixmaps::getInstance()->map1);
        } else if(_status == STATUS_MOVE){
            setPixmap(Pixmaps::getInstance()->map2);
        } else if(_status == STATUS_ATTACK){
            setPixmap(Pixmaps::getInstance()->map3);
        }
    }
}

void MapSquare::setUnitType(UNIT_TYPE new_type)
{
    _unit_type = new_type;
}

void MapSquare::setIndex(int r, int c)
{
    index_r = r;
    index_c = c;
}

void MapSquare::setSrc(int r, int c)
{
    _src_r = r;
    _src_c = c;
}

void MapSquare::setUnit(void *unit)
{
    _unit = unit;
}
